#encoding: utf-8
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
#   Mayor.create(name: 'Emanuel', city: cities.first)

role1 = Role.create({code: Constant::SYS_ADMIN_ROLE_CODE , name: '系统管理员'})
role2 = Role.create( {code:  Constant::SHIPPER_ROLE_CODE , name: '货主'})
role3 = Role.create( {code:  Constant::SHIPOWNER_ADMIN_ROLE_CODE, name: '船公司管理员'})
role4 = Role.create   ({code:  Constant::FORWARD_ADMIN_ROLE_CODE, name: '货代管理员'})
role5 = Role.create( {code: Constant::CY_ADMIN_ROLE_CODE, name: '场站管理员'})
role6 = Role.create( {code:  Constant::MOTORCADE_ADMIN_ROLE_CODE, name: '车队管理员'})
role30 = Role.create( {code:  Constant::SHIPOWNER_USER_ROLE_CODE, name: '船公司'})
role40 = Role.create   ({code:  Constant::FORWARD_USER_ROLE_CODE, name: '货代'})
role50 = Role.create( {code:  Constant::CY_USER_ROLE_CODE, name: '场站'})
role60 = Role.create( {code:  Constant::MOTORCADE_USER_ROLE_CODE, name: '车队'})
role70 = Role.create ({code: Constant::NO_ROLE_CODE, name: '禁用帐号'})

biz_unit1 = BizUnit.create(name: '跟踪平台', code: Constant::SYS_BIZ_UNIT_CODE, longitude: 1000001, latitude: 1000001)
biz_unit2 = Shipper.create(name: '货主', code: Constant::SHIPPER_BIZ_UNIT_CODE, longitude:1000001, latitude: 1000001)
weihai_shipowner = Shipowner.create(name: '威海船公司', code: 'WeihaiShip', longitude: 122150000, latitude: 37050000)
weihai_port = Port.create(name: '威海港口', code: 'WeihaiPort', longitude: 112150000, latitude: 37480000)
weihai_cy = Cy.create(name: '威海场站', code: 'WeihaiCy', longitude: 122070000, latitude: 37520000)
weihai_motorcade = Motorcade.create(name: '威海车队', code: 'WeihaiMotorcade', longitude: 122140000, latitude: 37420000)
weihai_forward = Forward.create(name: '威海货代', code: 'WeihaiForward', longitude:122110000, latitude:37530000)

admin = User.create(login: 'admin',  email: 'muwenzhong@163.com', password: 'admin', password_confirmation: 'admin', role_id: role1.id, biz_unit_id: biz_unit1.id)
shipper = User.create(login: 'shipper',  email: 'shipper@163.com', password: 'admin', password_confirmation: 'admin', role_id: role2.id, biz_unit_id: biz_unit2.id)
shipowner = User.create(login: 'shipowneradmin',  email: 'shipowner@163.com', password: 'admin', password_confirmation: 'admin', role_id: role3.id, biz_unit_id: weihai_shipowner.id)
shipowner = User.create(login: 'shipowner',  email: 'shipowner1@163.com', password: 'admin', password_confirmation: 'admin', role_id: role30.id, biz_unit_id: weihai_shipowner.id)
motorcade = User.create(login: 'motorcade',  email: 'motorcade@163.com', password: 'admin', password_confirmation: 'admin', role_id: role60.id, biz_unit_id: weihai_motorcade.id)
cy_user = User.create(login: 'cycycy',  email: 'cy@163.com', password: 'admin', password_confirmation: 'admin', role_id: role50.id, biz_unit_id: weihai_cy.id)
forward_user = User.create(login: 'forward',  email: 'forward@163.com', password: 'admin', password_confirmation: 'admin', role_id: role40.id, biz_unit_id: weihai_forward.id)
motorcade_admin = User.create(login: 'motorcadeadmin',  email: 'motorcadead@163.com', password: 'admin', password_confirmation: 'admin', role_id: role6.id, biz_unit_id: weihai_motorcade.id)
cy_admin = User.create(login: 'cycycyadmin',  email: 'cyad@163.com', password: 'admin', password_confirmation: 'admin', role_id: role5.id, biz_unit_id: weihai_cy.id)
forward_admin = User.create(login: 'forwardadmin',  email: 'forwardad@163.com', password: 'admin', password_confirmation: 'admin', role_id: role4.id, biz_unit_id: weihai_forward.id)


bl1 = Bl.create(bl_no: 'BL34567890123', status: 11, voyage: "V234567890", forward: weihai_forward, cy: weihai_cy, port: weihai_port, route: "route1", course: "E", shipowner: weihai_shipowner, shipper_name: "新北洋", user: shipper)
bl2 = Bl.create(bl_no: 'BL34567890125', status: 11, voyage: "V234567890", forward: weihai_forward, cy: weihai_cy, port: weihai_port, route: "route2", course: "W", shipowner: weihai_shipowner, shipper_name: "新北洋", user: shipper)
bl3 = Bl.create(bl_no: 'BL34567890130', status: 11, voyage: "V234567890", forward: weihai_forward, cy: weihai_cy, port: weihai_port, route: "route2", course: "W", shipowner: weihai_shipowner, shipper_name: "新北洋", user: shipper)
bl4 = Bl.create(bl_no: 'BL34567890131', status: 11, voyage: "V234567890", forward: weihai_forward, cy: weihai_cy, port: weihai_port, route: "route2", course: "W", shipowner: weihai_shipowner, shipper_name: "新北洋", user: shipper)
bl5 = Bl.create(bl_no: 'BL34567890132', status: 11, voyage: "V234567890", forward: weihai_forward, cy: weihai_cy, port: weihai_port, route: "route2", course: "W", shipowner: weihai_shipowner, shipper_name: "新北洋", user: shipper)
bl6 = Bl.create(bl_no: 'BL34567890133', status: 11, voyage: "V234567890", forward: weihai_forward, cy: weihai_cy, port: weihai_port, route: "route2", course: "W", shipowner: weihai_shipowner, shipper_name: "北洋集团", user: shipper)


bl_histroy1 = BlHistory.create(time: "2012-03-12 07:40:41", action: "派车", message: "7：40派车成功", bl: bl1)
bl_histroy2 = BlHistory.create(time: "2012-03-13 07:50:42", action: "出场", message: "7：40车辆出场", bl: bl1)

BlContainer.create(ctn_no: "BT45678999", status: 1, ctn_type: "20GP", seal_no: "QFH456", vehicle_no: "110098", bl: bl1)
bl_ctn1 = BlContainer.create(ctn_no: "BOX45678901", status: 1, ctn_type: "20GP", seal_no: "QFH456", vehicle_no: "110098", bl: bl1)
bl_ctn2 = BlContainer.create(ctn_no: "BOX45678902", status: 1, ctn_type: "20GP", seal_no: "QFH456", vehicle_no: "101280", bl: bl1)
bl_ctn3 = BlContainer.create(ctn_no: "BOX45678903", status: 1, ctn_type: "20GP", seal_no: "QFH456", vehicle_no: "200352", bl: bl2)

bl_ctn_history1 = BlContainerHistory.create(time: "2012-03-19 07:40:41", action: "派车", message: "7：40派车成功", bl_container: bl_ctn1, vehicle_no: '110098')
bl_ctn_history2 = BlContainerHistory.create(time: "2012-03-19 17:50:41", action: "出场", message: "7：50车辆出场", bl_container: bl_ctn1, vehicle_no: '110098')
bl_ctn_history3 = BlContainerHistory.create(time: "2012-03-20 15:40:43", action: "到客户", message: "8：40到达客户工厂仓库沈阳路009号", bl_container: bl_ctn1, vehicle_no: '110098')
bl_ctn_history4 = BlContainerHistory.create(time: "2012-03-20 19:40:44", action: "入场", message: "19：40入场", bl_container: bl_ctn1, vehicle_no: '110098')
bl_ctn_history5 = BlContainerHistory.create(time: "2012-03-20 20:40:44", action: "查验", message: "20：40查验", bl_container: bl_ctn1)
bl_ctn_history6 = BlContainerHistory.create(time: "2012-03-21 8:40:44", action: "放行", message: "8：40放行", bl_container: bl_ctn1)
bl_ctn_history4 = BlContainerHistory.create(time: "2012-03-21 19:40:44", action: "集港", message: "19：40集港", bl_container: bl_ctn1, vehicle_no: '200352')
bl_ctn_history4 = BlContainerHistory.create(time: "2012-03-21 22:40:44", action: "到港", message: "22：40到港", bl_container: bl_ctn1, vehicle_no: '200352')



bl_ctn2_history1 = BlContainerHistory.create(time: "2012-03-19 07:40:41", action: "派车", message: "7：40派车成功", bl_container: bl_ctn2, vehicle_no: '200352')
bl_ctn2_history2 = BlContainerHistory.create(time: "2012-03-19 17:50:41", action: "出场", message: "7：50车辆出场", bl_container: bl_ctn2, vehicle_no: '200352')
bl_ctn2_history3 = BlContainerHistory.create(time: "2012-03-20 18:40:43", action: "到客户", message: "8：40到达客户工厂仓库沈阳路009号", bl_container: bl_ctn2, vehicle_no: '200352')
bl_ctn2_history4 = BlContainerHistory.create(time: "2012-03-20 09:40:44", action: "入场", message: "9：40入场", bl_container: bl_ctn2, vehicle_no: '200352')

bl_ctn3_history1 = BlContainerHistory.create(time: "2012-03-19 07:40:41", action: "派车", message: "7：40派车成功", bl_container: bl_ctn3, vehicle_no: '101280')
bl_ctn3_history2 = BlContainerHistory.create(time: "2012-03-19 17:50:41", action: "出场", message: "7：50车辆出场", bl_container: bl_ctn3, vehicle_no: '101280')
bl_ctn3_history3 = BlContainerHistory.create(time: "2012-03-20 18:40:43", action: "到客户", message: "8：40到达客户工厂仓库沈阳路009号", bl_container: bl_ctn3, vehicle_no: '101280')
bl_ctn5_history4 = BlContainerHistory.create(time: "2012-03-20 19:40:44", action: "入场", message: "9：40入场", bl_container: bl_ctn3, vehicle_no: '101280')


supplier =  Supplier.create(name: "GPS提供商",key: "123456789", code: "GPS-SUPPLIER")

vehicle1 = Vehicle.create(vehicle_no: "110098", driver_name: "陈中", driver_phone: "13061356309", vehicle_type: "集装箱运输车", longitude: 122354500, latitude: 37051200, motorcade_id: weihai_motorcade.id, bl_no: bl1.bl_no)
vehicle2 = Vehicle.create(vehicle_no: "101280", driver_name: "王伟", driver_phone: "13361356309", vehicle_type: "集装箱运输车", longitude: 121354500, latitude: 36851200, motorcade_id: weihai_motorcade.id, bl_no: bl1.bl_no)
vehicle3 = Vehicle.create(vehicle_no: "200352", driver_name: "胡明", driver_phone: "13361356309", vehicle_type: "集装箱运输车", longitude: 121354500, latitude: 36851200, motorcade_id: weihai_motorcade.id, groups: 'personal', destination: '威海市沈阳路108号创业大厦2楼203', bl_no: bl2.bl_no)
vehicle4 = Vehicle.create(vehicle_no: "101281", driver_name: "胡明", driver_phone: "13361356309", vehicle_type: "集装箱运输车", longitude: 121354500, latitude: 36851200, motorcade_id: weihai_motorcade.id, groups: 'personal', destination: '威海市沈阳路108号创业大厦2楼203')
vehicle5 = Vehicle.create(vehicle_no: "101292", driver_name: "胡明", driver_phone: "13361356309", vehicle_type: "集装箱运输车", longitude: 121354500, latitude: 36851200, motorcade_id: weihai_motorcade.id, groups: 'personal', destination: '威海市沈阳路108号创业大厦2楼203')
vehicle6 = Vehicle.create(vehicle_no: "101288", driver_name: "胡明", driver_phone: "13361356309", vehicle_type: "集装箱运输车", longitude: 121354500, latitude: 36851200, motorcade_id: weihai_motorcade.id, groups: 'personal', destination: '威海市沈阳路108号创业大厦2楼203')
vehicle7 = Vehicle.create(vehicle_no: "101284", driver_name: "胡明", driver_phone: "13361356309", vehicle_type: "集装箱运输车", longitude: 121354500, latitude: 36851200, motorcade_id: weihai_motorcade.id, groups: 'personal', destination: '威海市沈阳路108号创业大厦2楼203')
vehicle8 = Vehicle.create(vehicle_no: "110701", driver_name: "胡明", driver_phone: "13361356309", vehicle_type: "集装箱运输车", longitude: 121354500, latitude: 36851200, motorcade_id: weihai_motorcade.id, groups: 'personal', destination: '威海市沈阳路108号创业大厦2楼203')